﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 异步_lambda
{
    public partial class Form1 : Form
    {
        //参考资料https://docs.microsoft.com/zh-cn/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions

        public Form1()
        {
            InitializeComponent();
            button1.Click += async (sender, e) => 
            {
                await TestMethodAsync();

                textBox1.Text+= "\r\nControl returned to Click event handler.\n"; ;
            };
        }

        private async void button1_Click(object sender, EventArgs e)
        {
            await TestMethodAsync();

            textBox1.Text += "\r\nControl returned to Click event handler.\n";
        }

        async Task TestMethodAsync()
        {
            await Task.Delay(3000);
        }
    }
}
